﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using Chinook.Core.DomainModel;

namespace Chinook.Core.FNHMappings
{
    public class InvoiceMap : ClassMap<Invoice>
    {
        public InvoiceMap()
        {
            //Table that has been referred to
            Table("Invoice");

            //Mapping for Primary key column
            Id(x => x.Id, "InvoiceId").GeneratedBy.Identity();
            //Map table Columns to POCO Fields
            Map(x => x.BillingAddress);
            Map(x => x.BillingCity);
            Map(x => x.BillingCountry);
            Map(x => x.BillingPostalCode);
            Map(x => x.BillingState);       
            Map(x => x.InvoiceDate);
            Map(x => x.Total);
            //One-to-one relationship
            References(x => x.Customer, "CustomerId").Cascade.None();
            //HasMany(x => x.Lines)
            //    .Access.Property()
            //    .AsBag()
            //    .Cascade.All()
            //    .LazyLoad()
            //    .Inverse()
            //    .KeyColumns.Add("InvoiceId", mapping => mapping.Name("InvoiceId") );  
            HasMany(x => x.Lines)              
               .KeyColumn("InvoiceId").Inverse().Cascade.All().AsBag().LazyLoad();  
        }
    }
}